package com.awen.htmlparser.util;

/**
 * 处理plainText的操作，比如TRIM\SUBSTR等
 * User: Administrator
 * Date: 13-4-12
 * Time: 下午4:35
 * To change this template use File | Settings | File Templates.
 */
public enum Operation {
    TRIM("TRIM"){
        @Override
        String process(String text, String... args) {
            return text.trim();  //To change body of implemented methods use File | Settings | File Templates.
        }
    },
    SUBSTR("SUBSTR"){
        @Override
        String process(String text, String... args){
            if(args.length < 1 || args.length > 2){
                throw new IllegalArgumentException();
            }
            if(args.length == 1){
                return text.substring(Integer.valueOf(args[0])).trim();
            }
            return text.substring(Integer.valueOf(args[0]), Integer.valueOf(args[1])).trim();
        }
    },
    /**
     * 根据传入的txt(图片路径)下载到指定目录（协议：ftp、disk....），并返回生成的图片全路径
     */
    DOWNIMG("DOWNIMG"){
        @Override
        String process(String text, String... args){

            String filePath = "";
            return filePath;
        }
    };
    private final String symbol;

    private Operation(String symbol) {
        this.symbol = symbol;
    }


    abstract String process(String text, String ...args);

    public String getSymbol() {
        return symbol;
    }
}
